package com.fcgzs.springboot.controller;


import com.fcgzs.springboot.service.UserService;
import com.fcgzs.springboot.util.Result;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wjd
 * @since 2021-10-12
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Reference
    private UserService userService;

    @RequestMapping("/getActiveUserInfo")
    public Result getActiveUserInfo(){
        //springsecurity提供全局对象，从中获得UserService中方法返回值的对象
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String username = user.getUsername();
        return new Result(true,"",username);
    }

    @RequestMapping("/getMenuByUname")
    public Result getMenuByUname(String username){
        return userService.getMenuByUname(username);
    }
}